package com.tgy.leetcode;

import javax.xml.crypto.Data;
import java.util.Arrays;

/**
 * @Author: tgy
 * @Date: 1/17/21 1:09 PM
 */
public class _1232_缀点成线 {

    public boolean checkStraightLine(int[][] coordinates) {

        if (coordinates == null || coordinates.length <= 1) {

            return true;
        }
//        // 排序
//        Arrays.sort(coordinates,(x1,x2)->{
//
//            return Integer.compare(x1[0],x2[0]);
//        });

        int m = coordinates[0][1] - coordinates[1][1];

        double cmp = Double.MAX_VALUE;
        if (m != 0) {

            cmp = Math.abs((coordinates[0][0] - coordinates[1][0])*1.0 / m);
        }

        for (int i = 2; i < coordinates.length; i++) {

            int n1 = (coordinates[i-1][0] - coordinates[i][0]);
            int n2 = (coordinates[i-1][1] - coordinates[i][1]);
            double cmp1 = Double.MAX_VALUE;
            if (n2 != 0) {
                cmp1 = Math.abs(n1*1.0/ n2);
            }

            if (cmp1 != cmp) {

                return false;
            }
        }

        return true;
    }

  public static void main(String[] args) {
    //

      _1232_缀点成线 line = new _1232_缀点成线();

      boolean result = line.checkStraightLine(new int[][]{{0, 0}, {0, 1}, {0,-1}});

        System.out.println(result);
  }

}
